home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 3_16.lha / 3_16 / 3_16.cmp < prev    next >
Text File  |  1993-08-08  |  1KB  |  112 lines

  1. include <stream.h>
  2. xtern void error(char *);
  3.  
  4. include "3_16b.c"         
  5. include "3_16c.c"         
  6. include "3_16d.c"         
  7. include "3_16a.c"         
  8.  
  9.  
  10.  
  11. include <stream.h>
  12.  
  13. nt main(int, char**)
  14.  
  15.    char ch;
  16.  
  17.    while (cin.get(ch))
  18. {
  19.  
  20. if (ch == '/')
  21.     {
  22.     cin.get(ch);
  23.     if (!cin)
  24.     break;
  25.  
  26.     if (ch == '/')    dolinecomment();
  27.     else if (ch == '*')    doblockcomment();
  28.  
  29.     
  30.     
  31.     
  32.     else
  33.     {
  34.     cout.put('/');
  35.     cin.putback(ch);
  36.     }
  37.     }
  38.  
  39. else            
  40.     {
  41.     cout.put(ch);
  42.     if (ch == '"' || ch == '\'')
  43.     do_string_or_char(ch);
  44.     }
  45. }
  46.    return 0;
  47.  
  48.  
  49. oid dolinecomment()
  50.  
  51.    char ch;
  52.  
  53.    
  54.    while (cin.get(ch))
  55. if (ch == '\n')
  56.     {
  57.     cout.put(ch);
  58.     return;
  59.     }
  60.  
  61.    error("EOF found within line comment");
  62.  
  63.  
  64. oid doblockcomment()
  65.  
  66.    cout.put(' ');
  67.    char ch;
  68.  
  69.    
  70.    while (cin.get(ch))
  71. if (ch == '*')
  72.     {
  73.     cin.get(ch);
  74.     if (ch == '/')
  75.     return;
  76.     cin.putback(ch);
  77.     }
  78.  
  79. else if (ch == '\n')
  80.     cout.put(ch);
  81.  
  82.    error("EOF found within full comment");
  83.  
  84.  
  85.  
  86.  
  87. oid do_string_or_char(char startquote)
  88.  
  89.    char ch;
  90.  
  91.    while (cin.get(ch))
  92. {
  93.  
  94. cout.put(ch);
  95.  
  96.  
  97. if (ch == startquote)
  98.     return;
  99.  
  100.  
  101. if (ch == '\\')
  102.     {
  103.     cin.get(ch);
  104.     if (!cin)
  105.     break;
  106.     cout.put(ch);
  107.     }
  108. }
  109.  
  110.    error("EOF found within string or char constant");
  111.  
  112.